package com.ht.aems.eas;

import com.ht.aems.dbservice.ConnectionFactory;
import com.ht.aems.fesmodel.FesPersistenceFactory;
import com.ht.log.DBTypes;
import com.ht.log.LoggerUtil;
import com.ht.log.MPLFactory;
import com.ht.memcached.MemCachedConfigurator;
import hhh.remoteService.utils.ServiceRegister;
import hhh.remoteService.utils.rmi.RmiRegistry;
import hhh.utils.FileUtil;
import hhh.utils.LogUtil;
import rtdb.RtDataHandler_MemCached;
import rtdb.RtMeasureHandler_MemoCached;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.rmi.RemoteException;

/**
 * Created by IntelliJ IDEA.
 * User: Dong Shufeng
 * Date: 11-10-10
 */
public class Main4Test {
    public static void main(String[] args) throws RemoteException, FileNotFoundException, InterruptedException {
        LogUtil.initialLog4j("eas/eas.log");
        RmiRegistry.setSpecifiedSocket();

        String f = FileUtil.getRootDirectory() + "/_config/memcache.properties";
        System.out.println("Load memcached config file : " + f);
        MemCachedConfigurator.config(f);

        f = FileUtil.getRootDirectory() + "/_config/dba.properties";
        System.out.println("Load database access config file : " + f);
        ConnectionFactory.setConfig(new FileInputStream(f));
        FesPersistenceFactory.setDatabase("shaems");
        FesPersistenceFactory.setType("sql");
        //just for test
        MPLFactory.initialDbType(DBTypes.DB_MYSQL);
        RtdbUtil.instance = "file";//for nari open3000 ems
        LoggerUtil.initialBufferSize(500);

        RtMeasureHandler_MemoCached rtMeasureHandler = new RtMeasureHandler_MemoCached();
        EasSysModel.INSTANCE.setRtMeasureQuery(rtMeasureHandler);
        EasSysModel.INSTANCE.setRtMeasureSaver(rtMeasureHandler);
        EasSysModel.INSTANCE.setRtDataHandler(new RtDataHandler_MemCached());

        ServiceRegister.registerService(EasFacade.class, RemoteEasFacade.instance, "eas");
        System.out.println("eas registered successfully!");

        while (true) {
            RemoteEasFacade.instance.loadPlans();
            RemoteEasFacade.instance.loadDeviceIds();
            RemoteEasFacade.instance.loadCalModel();
            RemoteEasFacade.instance.makeCommand();
            Thread.sleep(60000l);
        }
    }
}
